const Koa = require('koa')
const app = new Koa()
const Logger = require('koa-logger')

const md1 = async (ctx, next) => {
  ctx.type = 'text/html;utf-8'
  await next()
}

const md2 = async (ctx, next) => {
  ctx.body = 'hi'
  await next()
}

const md3 = async (ctx, next) => {
  ctx.body = 'hello, world'
}

/**
 * 
  before  0
  before  1
  before  2
  before  3
  after 3
  after 2
  after 1
  after 0
 */
// function tail(i) {
//   if (i > 3) return i
//   console.log("before ", i)
//   tail(i + 1)
//   console.log('after', i)
// }
// tail(0)


app.use(Logger())
app.use(md1)
app.use(md2)
app.use(md3)

app.listen(8181)